<!DOCTYPE html>
<html>
<head>
    <title>角色编辑</title>
    {% include 'system/common/header.html' %}</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ book.id }}" readonly name="id" lay-verify="title"
                               autocomplete="off" placeholder="请输入编号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ book.name }}" name="name" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">作者</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ book.auth }}"  name="auth" lay-verify="title"
                               autocomplete="off" placeholder="请输入作者" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="enable" {% if book.status == 1 %}checked {% endif %}value="1"
                               title="开启">
                        <input type="radio" name="enable" {% if book.status == 0 %}checked {% endif %} value="0"
                               title="关闭">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort" value="{{ book.sort }}" lay-verify="title" autocomplete="off"
                               placeholder="请输入排序"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">朝代</label>
                    <div class="layui-input-block">
                        <input placeholder="请输入朝代" type="text" value="{{ book.dynasty }}"  name="dynasty"
                               lay-verify="title"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">年份</label>
                    <div class="layui-input-block">
                        <input placeholder="请输入年份" name="year" type="text" value="{{ book.year }}"
                                   lay-verify="title" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">介绍</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入描述" name="desc" class="layui-textarea">{{ book.desc }}</textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="book-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'system/common/footer.html' %}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form
    let $ = layui.jquery

    form.on('submit(book-update)', function (data) {
      $.ajax({
        url: '/zbook/book/update',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'put',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
              parent.layui.table.reload('book-table')
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
<script>
</script>
</body>
</html>